好了我今天終於把小遊戲寫完了,突然覺得能撐過30天真的很了不起...
先來做拼圖補上的部分,這邊在Day6的DropPuzzle有留一個區塊是要用來做這個功能的
def dropPuzzle(self, x, y, drop_count):
if y - drop_count >= 0:
if self.all_gems[x][y- drop_count] != None:
self.all_gems[x][y] = self.all_gems[x][y- drop_count]
gem = self.getGemByPos(x, y)
gem.drop(drop_count)
self.all_gems[x][y- drop_count] = None
else:
self.dropPuzzle(x, y, drop_count + 1)
else:
# 產生新方塊
gem = Puzzle(type=random.choice(gem_imgs_list), position=[XMARGIN+x*GRIDSIZE, YMARGIN+y*GRIDSIZE])
self.all_gems[x][y] = gem
self.gems_group.add(gem)
return
其實邏輯很簡單,就只是創建新的物件而已
再來是自動消除,首先先把Day7的手動消除功能寫到function裡
def searchMatch(self):
for x in range(NUMGRID):
for y in range(NUMGRID):
if [x, y] not in self.check_is_matched_x:
self.nextMatchX(x, y, 0)
if [x, y] not in self.check_is_matched_y:
self.nextMatchY(x, y, 0)
if self.match_x != []:
for match_x in self.match_x:
self.matches.append(match_x)
if self.match_y != []:
for match_y in self.match_y:
self.matches.append(match_y)
# print(self.matches)
# 消除間隔
self.match_ticks = pygame.time.get_ticks()
注意一下最下面的match_ticks是記錄當下的時間,消除前會比對一下時間,不要讓它太快消除,改善一下觀感(?
呼叫這個function的時機分別為
這樣我的小遊戲就差不多完成了
最後放一下影片
https://youtu.be/XgZ5gVZazmg
程式碼在這邊
https://github.com/bsiotmceh-Tobey/triple-eliminate-game
明天終於可以來看看影像辨識了